/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lt.ntec.danblog.server.core.model.objectify;

import com.google.inject.Inject;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import lt.ntec.danblog.server.core.UserNotFoundException;
import lt.ntec.danblog.server.core.model.User;
import lt.ntec.danblog.server.core.model.UserDAO;

/**
 *
 * @author Tadas
 */
class ObjectifyUserDAO extends ObjectifyBaseDAO<User> implements UserDAO {

    static {
        ObjectifyService.register(ObjectifyUser.class);
    }
    
    @Inject
    public ObjectifyUserDAO(Objectify ofy) {
        super(ofy);
    }

    @Override
    public User getUserByEmail(String email) throws UserNotFoundException {
        ObjectifyUser get =
                ofy.query(ObjectifyUser.class).filter("email", email).get();
        if (get == null) {
            throw new UserNotFoundException();
        }
        
        return get;
    }

    @Override
    public Class<? extends User> getEntityClass() {
        return ObjectifyUser.class;
    }
}
